<template>
  <div>
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>

        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable @clear="clearEvent"></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" @click="dialogVisible=true" type="primary">新增配伍</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="tableData"
          border
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          size="medium"
          stripe
          style="width: 100%;font-size:12px"
        >
          <el-table-column type="index" width="50" align="center"></el-table-column>
          <el-table-column label="操作" width="100" align="center">
            <template slot-scope="scope">
              <el-button type="text" @click="ShowInvitOne(scope.row.articleId)">查看</el-button>
              <el-button type="text" @click="open(scope.row.articleId)">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="genId1Name" label="成分1" width="160" align="center"></el-table-column>
          <!-- <el-table-column prop="name"
                           label="操作"
                           width="60">
            <el-button type="text"
                       size="mini"
                       @click="dialogVisible = true">编辑</el-button>
          </el-table-column>-->
          <el-table-column prop="genId2Name" label="成分2" width="160" align="center"></el-table-column>
          <!-- routeType 给药类型 1  全身给药     2  局部给药  3  所有方式给药   0  系统默认 -->
          <el-table-column label="给药类型" width="100" align="center">
            <template
              slot-scope="scope"
            >{{(scope.row.routeType==1)?"全身给药":(scope.row.routeType==2)?"局部给药":(scope.row.routeType==3)?"所有方式给药":"系统默认"}}</template>
          </el-table-column>
          <!-- 警示级别 0：拦截 ，1：禁忌，2：不推荐，3：轻微 -->
          <el-table-column label="警示级别" width="90" align="center">
            <template
              slot-scope="scope"
            >{{(scope.row.slCode==-2)?"拦截":(scope.row.slCode==-1)?"忽略":(scope.row.slCode==0)?"拦截":(scope.row.slCode==1)?"禁忌":(scope.row.slCode==2)?"不推荐":(scope.row.slCode==3)?"轻微":(scope.row.slCode==4)?"轻微":(scope.row.slCode==5)?"重点提示":""}}</template>
          </el-table-column>
          <el-table-column prop="warning" label="警示信息" align="center"></el-table-column>
          <el-table-column prop="title" label="标题" align="center"></el-table-column>
          <el-table-column label="描述" align="left">
            <template slot-scope="scope">
              <div v-html="scope.row.abstractDesc"></div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog title="新增体外配伍" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
      <div class="addRuleAdverse">
        <el-form
          :inline="true"
          :model="addRuleData"
          class="demo-form-inline addForm"
          label-width="150px"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="成分1">
                <el-input v-model="addRuleData.genName1" size="medium">
                  <el-button slot="append" @click="selectGen(1)">选择</el-button>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="成分2">
                <el-input v-model="addRuleData.genName2" size="medium">
                  <el-button slot="append" @click="selectGen(2)">选择</el-button>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="给药类型">
                <el-select v-model="addRuleData.routeType" size="medium" placeholder="请选择">
                  <el-option
                    v-for="item in RouteOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="警示级别">
                <el-select v-model="addRuleData.slCode" size="medium" placeholder="请选择">
                  <el-option
                    v-for="item in SlOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="标题">
                <el-input v-model="addRuleData.title" type="textarea" :rows="5"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="描述">
                <el-input v-model="addRuleData.abstractDesc" type="textarea" :rows="5"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="警示信息">
            <!-- 大框 -->
            <el-input v-model="addRuleData.warning" type="textarea" :rows="5" placeholder="请输入内容"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addRule()">新 增</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 成分 -->
    <el-dialog
      title="选择成分"
      :visible.sync="GenVisible"
      class="editDialog"
      width="30%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:527px">
        <div class="addInput">
          <el-input v-model="AllerData.srm" size="small" placeholder="请输入内容"></el-input>
          <el-button
            style="margin-right:8px"
            type="primary"
            size="small"
            @click="SearchInVitro()"
          >搜索</el-button>
        </div>
        <el-table
          :data="AllerData.tableData"
          stripe
          border
          height="400"
          style="width: 100%;font-size: 10px"
          :header-cell-style="{'text-align':'center'}"
          :row-style="{height:'40px'}"
          :cell-style="{'text-align':'center',padding:'0px'}"
          @row-click="handleRow"
          @selection-change="handleSelectionChange"
        >
          <el-table-column label width="35">
            <template slot-scope="scope">
              <el-radio
                :label="scope.row"
                v-model="AllerData.radioId"
                @change.native="handleSelectionChange(scope.row)"
              ></el-radio>
            </template>
          </el-table-column>

          <el-table-column prop="id" width="150" label="成分编码"></el-table-column>
          <el-table-column prop="allerName" label="成分名称"></el-table-column>
        </el-table>
        <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
        <div class="dialogBlock">
          <el-pagination
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"
            current-page.sync="1"
            :page-size="100"
            layout="total, prev, pager, next"
            :total="AllerData.total"
          ></el-pagination>
        </div>
        <span slot="footer" class="dialog-footer">
          <div class="SortFoot">
            <el-button style="margin-right:8px" type="primary" size="small" @click="SelectRen()">确定</el-button>
            <el-button style="margin-right:8px" @click="RouteVisible = false" size="small">取消</el-button>
          </div>
        </span>
      </div>
    </el-dialog>
    <!-- 查看成分 -->
    <el-dialog title="查看成分" :visible.sync="InvitOneVisible" width="50%" :before-close="handleClose">
      <div class="addRuleAdverse">
        <el-form
          :inline="true"
          :model="InvitOneData"
          class="demo-form-inline addForm"
          label-width="150px"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="成分1">
                <el-input disabled v-model="InvitOneData.genId1" size="medium">
                  <!-- <el-button slot="append" disabled @click="selectGen(3)">选择</el-button> -->
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="成分2">
                <el-input disabled v-model="InvitOneData.genId2" size="medium">
                  <!-- <el-button slot="append" disabled @click="selectGen(4)">选择</el-button> -->
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="给药类型">
                <el-select v-model="InvitOneData.routeType" size="medium" placeholder="请选择">
                  <el-option
                    v-for="item in RouteOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="警示级别">
                <el-select v-model="InvitOneData.slCode" size="medium" placeholder="请选择">
                  <el-option
                    v-for="item in SlOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="标题">
                <el-input v-model="InvitOneData.title" type="textarea" :rows="5"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="描述">
                <el-input
                  v-model="InvitOneData.abstractDesc"
                  type="textarea"
                  :rows="5"
                  size="medium"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="警示信息">
            <!-- 大框 -->
            <el-input v-model="InvitOneData.warning" type="textarea" :rows="5"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="upDataInvitro()">更 新</el-button>
        <el-button @click="InvitOneVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getInVitroList, getAllergen } from "@/api/rad";
export default {
  data() {
    return {
      multipleSelection: {},
      queryInfo: {
        srm: "",
        // routeType: "", //注射液给药途径类型 1-大输液，2-注射器
        // slcode: "", //警示级别 0:拦截，1：禁忌，2：不推荐，3：轻微
        page: 1, //当前页数
        pageSize: 20, //每页显示的数量
      },
      total: 0,
      tableData: [],
      dialogVisible: false,
      addRuleData: {
        load: 0,
        genId1: "",
        genName1: "",
        genId2: "",
        genName2: "",
        routeType: "",
        slCode: "",
        warning: "",
        title: "",
        abstractDesc: "",
        articleId: "",
      },
      Typeoption: [
        {
          value: "",
          label: "全部",
        },
        {
          value: 1,
          label: "大输液",
        },
        {
          value: 2,
          label: "注射器",
        },
      ],
      slcodeoption: [
        {
          value: "",
          label: "全部",
        },
        {
          value: 0,
          label: "拦截",
        },
        {
          value: 1,
          label: "禁忌",
        },
        {
          value: 2,
          label: "不推荐",
        },
        {
          value: 3,
          label: "轻微",
        },
      ],
      RouteOptions: [
        {
          value: 3,
          label: "所有方式给药",
        },
        {
          value: 1,
          label: "全身给药",
        },
        {
          value: 2,
          label: "局部给药",
        },
        {
          value: 0,
          label: "系统默认",
        },
      ],
      SlOptions: [
        {
          value: 0,
          label: "拦截",
        },
        {
          value: 1,
          label: "禁忌",
        },
        {
          value: 2,
          label: "不推荐",
        },
        {
          value: 3,
          label: "轻微",
        },
      ],
      GenVisible: false,
      AllerData: {
        srm: "",
        page: 1,
        pageSize: 20,
        tableData: [],
        total: 0,
        radioId: [],
      },
      InvitOneVisible: false,
      InvitOneData: {
        InvitOneData: "",
        id: "",
        genId1: "",
        genId2: "",
        routeType: "",
        slCode: "",
        warning: "",
        title: "",
        abstractDesc: "",
      },
    };
  },
  created: function () {
    this.getInVitroList();
  },
  methods: {
    handleClose(done) {
      done();
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getInVitroList();
    },
    handleSizeChange1(newSize) {
      this.AllerData.pageSize = newSize;
      this.getAllergen();
    },

    handleCurrentChange1(newPage) {
      this.AllerData.page = newPage;
      this.getAllergen();
    },
    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage;
      this.getInVitroList();
    },
    async getInVitroList() {
      console.log(this.queryInfo);
      let res = await this.$rad.getInVitroList({
        srm: this.queryInfo.srm,
        page: this.queryInfo.page,
        pageSize: this.queryInfo.pageSize,
      });
      (this.tableData = res.rows), (this.total = res.total);
      console.log(res);
    },
    getSearchList() {
      this.getInVitroList();
    },
    clearEvent(load) {},
    selectGen(load) {
      this.addRuleData.load = load;
      this.GenVisible = true;
      this.getAllergen();
    },
    async getAllergen() {
      console.log(this.AllerData);
      let res = await this.$rad.getAllergen({
        srm: this.AllerData.srm,
        page: this.AllerData.page,
        pageSize: this.AllerData.pageSize,
      });
      console.log(res);
      this.AllerData.tableData = res.rows;
      this.AllerData.total = res.total;
    },
    SelectRen() {
      if (this.AllerData.radioId.length == 0) {
        return this.$message({
          type: "warning",
          message: "未选择成分",
        });
      } else {
        if (this.addRuleData.load == 1) {
          this.addRuleData.genId1 = this.AllerData.radioId.id;
          this.addRuleData.genName1 = this.AllerData.radioId.allerName;
        } else if (this.addRuleData.load == 2) {
          this.addRuleData.genId2 = this.AllerData.radioId.id;
          this.addRuleData.genName2 = this.AllerData.radioId.allerName;
        }
      }

      // else if (this.addRuleData.load == 3) {
      //   this.InvitOneData.genId1 = this.AllerData.radioId.id;
      //   this.InvitOneData.genName1 = this.AllerData.radioId.allerName;
      // } else if (this.addRuleData.load == 4) {
      //   this.InvitOneData.genId2 = this.AllerData.radioId.id;
      //   this.InvitOneData.genName2 = this.AllerData.radioId.allerName;
      // }
      this.GenVisible = false;
      this.AllerData.srm = "";
    },
    async addRule() {
      if (this.addRuleData.genId1 === "") {
        this.$message({
          type: "warning",
          message: "请选择成分1",
        });
      } else if (this.addRuleData.genId2 === "") {
        this.$message({
          type: "warning",
          message: "请选择成分2",
        });
      } else if (this.addRuleData.routeType === "") {
        this.$message({
          type: "warning",
          message: "请选择给药类型",
        });
      } else if (this.addRuleData.slCode === "") {
        this.$message({
          type: "warning",
          message: "请选择警示级别",
        });
      } else if (this.addRuleData.warning === "") {
        this.$message({
          type: "warning",
          message: "警示信息为空",
        });
      } else if (this.addRuleData.title === "") {
        this.$message({
          type: "warning",
          message: "标题为空",
        });
      } else if (this.addRuleData.abstractDesc === "") {
        this.$message({
          type: "warning",
          message: "描述为空",
        });
      } else {
        console.log(this.addRuleData);
        let res = await this.$rad.addRuleIvInfo({
          genId1: this.addRuleData.genId1,
          genId2: this.addRuleData.genId2,
          routeType: this.addRuleData.routeType,
          slCode: this.addRuleData.slCode,
          warning: this.addRuleData.warning,
          title: this.addRuleData.title,
          abstractDesc: this.addRuleData.abstractDesc,
          // articleId: this.addRuleData.articleId
        });
        console.log(res);
        if (res.code == 1) {
          this.dialogVisible = false;
          this.getInVitroList();

          return this.$message({
            type: "success",
            message: res.msg,
          });
        } else {
          return this.$message({
            type: "error",
            message: res.msg,
          });
        }
      }
    },
    async ShowInvitOne(articleId) {
      this.InvitOneVisible = true;
      this.InvitOneData.articleId = articleId;
      let res = await this.$rad.ShowInvitOne({
        articleId: articleId,
      });
      console.log(res);
      (this.InvitOneData.id = res.data.id),
        (this.InvitOneData.genId1 = res.data.genId1Name),
        (this.InvitOneData.genId2 = res.data.genId2Name),
        (this.InvitOneData.routeType = res.data.routeType),
        (this.InvitOneData.slCode = res.data.slCode),
        (this.InvitOneData.warning = res.data.warning),
        (this.InvitOneData.title = res.data.title),
        (this.InvitOneData.abstractDesc = res.data.abstractDesc);
    },
    async upDataInvitro() {
      console.log(this.InvitOneData);
      let res = await this.$rad.upDataInvitro({
        articleId: this.InvitOneData.articleId,
        id: this.InvitOneData.id,
        genId1: this.InvitOneData.genId1,
        genId2: this.InvitOneData.genId2,
        routeType: this.InvitOneData.routeType,
        slCode: this.InvitOneData.slCode,
        warning: this.InvitOneData.warning,
        title: this.InvitOneData.title,
        abstractDesc: this.InvitOneData.abstractDesc,
      });
      console.log(res);
      if (res.code == 1) {
        this.InvitOneVisible = false;
        this.getInVitroList();
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$message({
          type: "error",
          message: res.msg,
        });
      }
    },
    open(articleId) {
      this.$confirm("此操作将永久删除该规则, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.DeleteInvitOne(articleId);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    async DeleteInvitOne(articleId) {
      let res = await this.$rad.DeleteInvitOne({
        articleId: articleId,
      });
      console.log(res);
      if (res.code == 1) {
        this.getInVitroList();
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$$message({
          type: "error",
          message: res.msg,
        });
      }
      this.getInVitroList();
    },
    handleRow(row) {
      console.log(row);
      this.AllerData.radioId = row;
      this.multipleSelection = row;
    },
    handleSelectionChange(val) {
      console.log(res);
      this.multipleSelection = val;
    },
    SearchInVitro() {
      this.getAllergen();
    },
  },
};
</script>
<style scoped>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
.editDialog >>> .el-dialog__header {
  margin-bottom: 0px;
}
.editDialog >>> .el-dialog__body {
  padding-left: 0px;
  padding-right: 0px;
}
.addInput {
  height: 45px;
  display: flex;
  align-items: center;
}
.SortFoot {
  height: 50px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.addInput >>> .el-input {
  width: 40%;
  margin-left: 8px;
}
.addInput >>> .el-button {
  margin-left: 8px;
}
.dialogBlock {
  margin-top: 0px;
  margin-bottom: 0px;
}
.adverseCard >>> .el-input {
  width: 60%;
}
.adverseCard >>> .el-input {
  width: 120px;
}
.addForm >>> .el-form-item__content {
  width: 200px;
}
</style>